<?php
// 本类由系统自动生成，仅供测试用途
class CenterAction extends Action {
    function _initialize(){
         $this->CheckLogin();
//        $_SESSION['uid']=1;
//        $_SESSION['uname']='小杜';
         if($_GET['gid']){ 
            $group=M('Groups');//group_sort'
            $data['gid']=$_GET['gid'];
            $group=$group->where($data)->find();
            //dump($group);
            $this->assign('Group',$group);
            //查询关键字
            $keydata['main_id']=$data['gid'];
            $keydata['type']='groups';
            $keyword=D('KeywordView');
            $keylist=$keyword->where($keydata)->field('id,key_name,key_count')->select();
            $this->assign('mainkey_list',$keylist);
            $this->assign('gid',$_GET['gid']);
         }
     
    }
    protected function  CheckLogin(){
         if(!isset($_SESSION[C('USER_AUTH_KEY')])) {
           //  dump($_SESSION[C('USER_AUTH_KEY')]);
                 $this->assign('jumpUrl','__APP__/Center/Login/');
                $this->error('没有登录,请先登录!');
        }
    }
    //发送邮件
    function sendemail($email,$group){
            $title = '您的好友邀请您加入群组:'.$group;  //标题
            
            $nowtime=date("Y年m月d日 H:i:s",time());
                //生成验证码
            $rs= $this->randStr($l=20);
            //邮件内容
            $content ='亲爱的用户：
             '
.'您好！'
.''
.'              您的好友,邀请您加入群组'.$group.',点击链接此加入该群:'
.''
.              'http://www.sameus.com/Center/Login/Rvalidate?getpassresetpwd&validate='.md5($rs).'&email='.$email.''
.''
.'              (如果您无法点击此链接，请将它复制到浏览器地址栏后访问)'
.''
.'              为了保证您帐号的安全，该链接有效期为24小时，并且点击一次后失效！'
.''
.''
.'同众网'.$nowtime;
             //将邮箱和验证码加入验证表中,等待验证
                $vl=M('Validate');
                
                $data['email']=$email;
                $this->assign('email',$email);
              //  $data['time']=array('egt',time()-60);

                if($vl->where($data)->find()){

                    $data['validate']=md5($rs);
                    $data['time']=time();
                    $vl->save($data);

                }else{

                    $data['validate']=md5($rs);
                    $data['time']=time();
                    $vl->add($data);

                }
               if(SendMail($email,$title,$content)){
                    return true;
                }else{
                    return false; 
                }; 
                
    }
    //生成随机字母
    function randStr($l){
              $str = "abcdefghijklmnopqrstuvwxyz";
              $finalStr = "";
              for($j = 0;$j < $l;$j++)
              {
                $finalStr .= substr($str,rand(0,25),1);
              }
              return $finalStr;
    } 
}